package com.msda.controller;


import com.msda.pojo.dto.PageDTO;
import com.msda.pojo.dto.room.RoomDTO;
import com.msda.pojo.entity.order.Reservation;
import com.msda.pojo.entity.requirement.MeetingRoomSearchParams;
import com.msda.pojo.entity.requirement.Requirement;
import com.msda.pojo.entity.room.MeetingRoom;
import com.msda.pojo.vo.RoomOrderDetail;
import com.msda.service.room.RoomService;
import com.msda.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.zip.DataFormatException;

@CrossOrigin
@RestController
@RequestMapping("/meeting_room")
@Validated
@Tag(name = "会议室", description = "对会议室进行操作")
public class RoomController {
    @Autowired
    private RoomService roomService;

    @Operation(summary = "添加会议室")
    @PostMapping("/add_room")
    public Result<String> addRoom(@RequestBody RoomDTO roomDTO){
        return Result.success(roomService.addRoom(roomDTO));
    }


    @Operation(summary = "根据Id获得会议室信息")
    @PostMapping("/get_room_by_id/{roomId}")
    public Result<MeetingRoom> getUser(@PathVariable String roomId){
        return Result.success(roomService.getRoomById(roomId));
    }

    @Operation(summary = "删除会议室")
    @PostMapping("/delete_room/{roomId}")
    public Result<String> deleteUser(@PathVariable String roomId){
        return Result.success("删除User数据条数:" + roomService.deleteRoom(roomId));
    }

    @Operation(summary = "更新会议室")
    @PostMapping("/update_room")
    public Result<MeetingRoom> updateRoom(@RequestBody RoomDTO roomDTO) throws DataFormatException {
        return Result.success(roomService.updateRoom(roomDTO));
    }



    @Operation(summary = "获取所有会议室条数")
    @PostMapping("/get_all_room_Count")
    public Result<Long> getAllRoom() {
        return Result.success(roomService.getAllRoomCount());
    }

    @Operation(summary = "分页获取会议室信息")
    @PostMapping("/get_page_room")
    public Result<List<MeetingRoom>> getPageRoom(@RequestBody PageDTO pageDTO) {
        return Result.success(roomService.getPageRoom(pageDTO));
    }

    @Operation(summary = "根据条件查询会议室")
    @PostMapping("/get_room_by_requirement")
    public Result<List<MeetingRoom>> getRoomByRequirement(@RequestBody Requirement requirement) {
        return Result.success(roomService.getRoomByRequirement(requirement));
    }

    @Operation(summary = "管理员筛选会议室")
    @PostMapping("/admin_search_room")
    public Result<List<MeetingRoom>> adminSearchRoom(@RequestBody MeetingRoomSearchParams meetingRoomSearchParams) {
        return Result.success(roomService.adminSearchRoom(meetingRoomSearchParams));
    }

    @Operation(summary = "查找正在被使用的会议室")
    @PostMapping("/search_using_meetingRoom")
    public Result<?> searchUsingMeetingRoom() {
        return Result.success(roomService.searchUsingMeetingRoom());
    }

    @Operation(summary = "根据会议室id获得现在有的预订单订单以及开始时间结束时间和日期")
    @PostMapping("/search_order_byMeetingRoom/{meetingRoomId}")
    public Result<List<RoomOrderDetail>> searchOrderByMeetingRoomId(@PathVariable String meetingRoomId) {
        return Result.success(roomService.searchOrderByMeetingRoomId(meetingRoomId));
    }
}
